package message

import (
	"npxy-go/pkg/tcp"
)

type identicalMessage struct {
	Id        int32
	LocalPort uint16
}

func (i *identicalMessage) Decode(buf *tcp.Buffer) {
	i.Id = buf.ReadInt32()
	i.LocalPort = buf.ReadUInt16()
}

type ConnectionMessage struct {
	identicalMessage
}

type DisconnectionMessage struct {
	identicalMessage
}

type ForwardMessage struct {
	identicalMessage
}

func (i *ConnectionMessage) Encode(buf *tcp.Buffer) {
	buf.AddUInt16(i.LocalPort)
	buf.AddInt32(i.Id)
	buf.AddInt8(int8(CONNECTION))
}
func (i *DisconnectionMessage) Encode(buf *tcp.Buffer) {
	buf.AddUInt16(i.LocalPort)
	buf.AddInt32(i.Id)
	buf.AddInt8(int8(DISCONNECTION))
}
func (i *ForwardMessage) Encode(buf *tcp.Buffer) {
	buf.AddUInt16(i.LocalPort)
	buf.AddInt32(i.Id)
	buf.AddInt8(int8(FORWARD))
}
